﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

using System.Data.Entity;
using DAO;

namespace BUS
{
    public class BUS_WRLANGUAGE
    {
        WRMOEntities db = new WRMOEntities();

        public IList<WRLANGUAGE> _GetList()
        {
            return db.WRLANGUAGEs.ToList();
        }

        public IList<WRLANGUAGE> _GetList(Func<WRLANGUAGE, bool> cond)
        {
            return db.WRLANGUAGEs.Where(cond).ToList();
        }

        public WRLANGUAGE _GetObject(int ID)
        {
            return db.WRLANGUAGEs.Where(p => p.ID == ID).FirstOrDefault();
        }

        public WRLANGUAGE _GetObject(Func<WRLANGUAGE,bool> cond)
        {
            return db.WRLANGUAGEs.Where(cond).FirstOrDefault();
        }

        public WRLANGUAGE _CreateObject()
        {
            return db.WRLANGUAGEs.CreateObject();
        }

        public void _Save()
        {
            db.SaveChanges();
        }

        public void _Add(WRLANGUAGE entity, bool save = true)
        {
            try
            {
                db.AddToWRLANGUAGEs(entity);
                if (save)
                    _Save();
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }

        public void _Update(WRLANGUAGE entity)
        {
            try
            {
                WRLANGUAGE _mainEntity = db.WRLANGUAGEs.Where(p => p.ID == entity.ID).FirstOrDefault();
                if (_mainEntity != null)
                {
                    _mainEntity.ID = entity.ID;
                    _mainEntity.LangName = entity.LangName;
                    _mainEntity.LangCode = entity.LangCode;
                    _mainEntity.UpdateDate = entity.UpdateDate;
                    _mainEntity.IDUpdateBy = entity.IDUpdateBy;
                    _mainEntity.LangDescription = entity.LangDescription;
                    _mainEntity.Active = entity.Active;
                    _mainEntity.Keywords = entity.Keywords;
                }
                _Save();
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }

        public void _Delete(int ID)
        {
            try
            {
                WRLANGUAGE _mainEntity = db.WRLANGUAGEs.Where(p => p.ID == ID).FirstOrDefault();
                if (_mainEntity != null)
                {
                    db.WRLANGUAGEs.DeleteObject(_mainEntity);
                }
                _Save();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public void _Delete(WRLANGUAGE entity)
        {
            try
            {
                WRLANGUAGE _mainEntity = db.WRLANGUAGEs.Where(p => p.ID == entity.ID).FirstOrDefault();
                if (_mainEntity != null)
                {
                    db.WRLANGUAGEs.DeleteObject(_mainEntity);
                }
                _Save();
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }
        public DataTable Get_Language_List()
        {
            IList<Get_Language_List_Result> query = db.Get_Language_List().ToList();
            return Common.Common.ConvertToDataTable(query.ToList());
        }
    }
}
